package com.dongjiantong.quarantine.serviceImpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongjiantong.mybatis.ServiceMybatis;
import com.dongjiantong.quarantine.mapper.DjtButcherReportsMapper;
import com.dongjiantong.quarantine.model.DjtButcherReports;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by mz on 18/11/17.
 *
 */
@Slf4j
@Service(version = "1.0.0")
public class DjtButcherReportsReadServiceImpl extends ServiceMybatis<DjtButcherReports> implements DjtButcherReportsReadService{

    @Resource
    private DjtButcherReportsMapper djtButcherReportsMapper;

    /**
     * 查询单据详情
     *
     * @param id 主键id
     * @return DjtButcherReports
     */
    @Override
    public DjtButcherReports findById(Long id) {
        return djtButcherReportsMapper.selectByPrimaryKey(id);
    }


    /**
     * 获取但钱单据状态
     *
     * @param id 单据主键id
     * @return Integer status
     */
    @Override
    public Integer findStatusById(Long id) {
        return djtButcherReportsMapper.findStatusById(id);
    }

    /**
     * 屠宰端分页查询
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @param map      参数
     * @return PageInfo<DjtButcherReports>
     */
    @Override
    public PageInfo<DjtButcherReports> pagingForButcher(Integer pageNo, Integer pageSize, Map<String, Object> map) {
        PageHelper.startPage(pageNo, pageSize);

        List<DjtButcherReports> djtButcherReportsList = djtButcherReportsMapper.selectListForButcher(map);

        PageInfo<DjtButcherReports> butcherReportsPageInfo = new PageInfo<DjtButcherReports>(djtButcherReportsList);
        return butcherReportsPageInfo;
    }

    /**
     * 政府端的分页查询
     *
     * @param pageNo   页码
     * @param pageSize 每页多少条
     * @param map      参数
     * @return PageInfo<DjtButcherReports>
     */
    @Override
    public PageInfo<DjtButcherReports> pagingForGOV(Integer pageNo, Integer pageSize, Map<String, Object> map) {
        if(map == null) map = Maps.newHashMap();

        PageHelper.startPage(pageNo, pageSize);

        List<DjtButcherReports> djtButcherReportsList = djtButcherReportsMapper.selectListForGOV(map);

        PageInfo<DjtButcherReports> butcherReportsPageInfo = new PageInfo<DjtButcherReports>(djtButcherReportsList);
        return butcherReportsPageInfo;
    }

    /**
     * 根据入场的单据好查询 屠宰检疫单据的id
     *
     * @param admissionId 入场的单据的id
     * @return Long
     */
    @Override
    public Long checkIsExist(Long admissionId) {
        Map<String , Object> map = Maps.newHashMap();
        map.put("admissionId",admissionId);
        return djtButcherReportsMapper.checkIsExist(map);
    }
}
